package com.mapper;

import com.bean.Activity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Yuicon on 2017/3/20.
 */
@Repository
public interface ActivityMapper {

    @Select("select id,title,content,themeImg,activitiesAddress,startTime,endTime,likeNumber," +
            "deadline,launchTime,readNumber,willNumber,user_id as userId from tb_activity where id = #{id}")
    Activity findById(String id);

    @Select("select * from tb_activity order by deadline desc")
    List<Activity> findAll();

    @Select("select * from tb_activity where user_id = #{userId}")
    List<Activity> findByUserId(String userId);

    @Insert("insert into tb_activity(id,title,content,themeImg,activitiesAddress,startTime,endTime," +
            "deadline,launchTime,user_id) " +
            "values(#{id},#{title},#{content},#{themeImg},#{activitiesAddress},#{startTime},#{endTime}," +
            "#{deadline},#{launchTime},#{userId})")
    int insert(Activity activity);

    @Delete("delete from tb_activity where id = #{id}")
    int deleteById(String id);

    @Update("update tb_activity set content = #{content}, title = #{title}, readNumber = #{readNumber}," +
            "likeNumber = #{likeNumber}, willNumber = #{willNumber}, readNumber = #{readNumber}, " +
            "readNumber = #{readNumber} where id = #{id}")
    int update(Activity activity);

}
